package com.example.orderform.dao;

import com.example.orderform.vo.Order;
import com.example.orderform.vo.Refund;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface DeliverGoodsMapper {
    @Select("select * from order_copy1 where orderstatus='买家已付款' and userid=${userid} LIMIT #{q},#{j}")
    List<Order> delivercha(int q,int j,int userid);

    @Select("select count(*) from order_copy1 where orderstatus='买家已付款' and userid = ${userid} ")
    int delivcha(@Param("userid") int userid);

    @Select("select * from order_copy1 where orderid=${orderid}")
    Order deliorderxq(String orderid);


    @Select("select * from order_copy1 where ordernumber='${ordernumber}'")
    List<Order> mhseleordernumber(@Param("ordernumber") String ordernumber);

    @Update("update `order_copy1` set orderstatus='退款中的订单' where ordernumber='${ordernumber}'")
    int tuikuang(String ordernumber);

    @Select("select * from order_copy2 where userid=${userid}")
    List<Refund> tuikuancha(int userid);

    @Select("select undertime from order_copy1 where orderid=#{orderid}")
    String daihundjs(int orderid);

    @Update("update `order_copy1` set orderstatus='卖家已发货',statusbutton='确认收货',statusbuttonunder='退货退款' where orderid=${orderid}")
    int daihuogai(int orderid);


    @Insert("insert into order_copy2(userid,ordernumber,servicetype,cargostatus,price,refundreason,refundinstructions,shoopname,ordercolor,ordersieze,picture,updatime,tkstatus) values(${userid},'${ordernumber}','${servicetype}','${cargostatus}','${price}','${refundreason}','${refundinstructions}','${shoopname}','${ordercolor}','${ordersieze}','${picture}',NOW(),'退款中的订单')")
    int addordertow(@Param("userid")int userid,
                    @Param("ordernumber")String ordernumber,
                    @Param("servicetype")String servicetype,
                    @Param("cargostatus")String cargostatus,
                    @Param("price")String price,
                    @Param("refundreason")String refundreason,
                    @Param("refundinstructions")String refundinstructions,
                    @Param("shoopname")String shoopname,
                    @Param("ordercolor")String ordercolor,
                    @Param("ordersieze")String ordersieze,
                    @Param("picture")String picture);



    //待发货
    @Select("select * from order_copy1 where orderstatus='买家已付款' and userid=${userid} LIMIT #{q},#{j}")
    List<Order> daifahuo(int q,int j,int userid);

    //待发货改状态
    @Update("update order_copy1 set orderstatus='卖家已发货' where orderid='${orderid}'")
    int backfahuo(int orderid);

    @Select("select * from order_copy1 where orderstatus='卖家已发货' and userid='${userid}'")
    List<Order> selefahuo(int userid);

    //退款中
    @Select("select * from order_copy2 where userid=${userid} and tkstatus='退款中的订单'")
    List<Refund> selecopy2(int userid);
   //退款成功
    @Select("select * from order_copy2 where userid=${userid} and tkstatus='退款成功'")
    List<Refund> selecopys2(int userid);

    //同意退款修改表copy1
    @Update("update order_copy1 set orderstatus='退款成功' where orderid='${orderid}' ")
    int backcopy1(int orderid);

    //同意退款修改表copy2
    @Update("update order_copy2 set tkstatus='退款成功' where id='${id}' ")
    int backcopy2(int id);

    //不同意退款修改表copy1
    @Update("update order_copy1 set orderstatus='买家已付款' where orderid='${orderid}' ")
    int backcopy3(int orderid);



}
